package io.yizoo.business.controller;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.yizoo.business.entity.biz_hrm_ei_career;
import io.elm.core.CoreController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.EnumSet;
import java.util.List;

@RestController
@RequestMapping("/business/my/ei/career")
public class my_ei_careerController extends CoreController {
    @Override
    protected void Init() {
        PowerEntity = biz_hrm_ei_career.class;
        PowerUse = EnumSet.of(Power.IDDelete, Power.IDAny, Power.IDGetSingle,Power.IDUpsert);
    }

    @PostMapping("/GetData")
    public Object GetData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .From(biz_hrm_ei_career.class)
                        .Where("and ei_id=#{ei_id}", "ei_id")
                        .Where("and type=#{type}","type")
                        .GetFactor());
        return JsonResult(ret);
    }

    @PostMapping("/Save")
    public Object Save(@RequestBody String jsonStr) {
        ObjectNode node = Ctor.getObjectNode(jsonStr);
        int ret = Ctor.HMapper.Save(biz_hrm_ei_career.class,
                (ArrayNode) node.get("items"),
                Ctor.DMaker().Deleter
                        .putFactorItem("ei_id",node.get("ei_id").asText())
                        .putFactorItem("type",node.get("type").asText())
                        .From(biz_hrm_ei_career.class)
                        .Where("and ei_id=#{ei_id} and type=#{type}","ei_id","type")
                        .GetFactor());
        return JsonResult(ret);
    }
}
